<template>
  <div>
    <!-- 司机登记表单区域 -->
    <div class="list">
      <h2>司机登记</h2>
      <el-form label-width="110px" :rules="listRules" :model="list">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name1">
              <el-input v-model="list.name1"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="IdNumber">
              <el-input v-model="list.IdNumber"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio v-model="list.sex" label="1">男</el-radio>
              <el-radio v-model="list.sex" label="2">女</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生年月" prop="birth">
              <el-date-picker v-model="list.birth" type="date" placeholder="选择日期" style="width: 250px;">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="居住地址" prop="address">
          <el-input v-model="list.address" style="width:624px"></el-input>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="已持有驾照">
              <div class="checkbox">
                <el-checkbox label="A" border></el-checkbox>
                <el-checkbox label="B" border></el-checkbox>
                <el-checkbox label="C" border></el-checkbox>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="PhoneNumber1">
              <el-input v-model="list.PhoneNumber1"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="紧急联系人" prop="name2">
              <el-input v-model="list.name2"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="紧急联系电话" style="width: 200px" prop="PhoneNumber2">
              <el-input v-model="list.PhoneNumber2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 图片上传区域 -->
    <div class="picture">
      <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false">
        <img v-if="imageUrl" :src="imageUrl" class="avatar" alt="">
        <i v-else class="uppic">照片</i>
      </el-upload>
    </div>
    <!-- 图片区域 -->
    <div class="pic">
      <span class="demonstration">车辆图片</span>
      <el-carousel height="180px" style="border-radius: 25px">
        <el-carousel-item v-for="item in 4" :key="item">
          <h3 class="small">{{ item }}</h3>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="a">
      <el-button type="primary" @click="add">确定登记</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //司机登记表单的数据绑定
      list: {
        name1: '',
        name2: '',
        birth: '',
        sex: '',
        IdNumber: '',
        address: '',
        DrivingLicense: '',
        PhoneNumber1: '',
        PhoneNumber2: '',
      },
      //照片的数据绑定
      imageUrl: '',
      //登记表单的验证规则对象
      listRules: {
        //验证姓名是否为空
        name1: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ],
        //验证身份证号码是否为18位
        IdNumber: [
          {required: true, message: '请输入身份证号', trigger: 'blur'},
          {min: 18, max: 18, message: '身份证号应为18位哦', trigger: 'blur'}
        ],
        //验证居住地址是否为空
        address: [
          {required: true, message: '请输入你的居住地址', trigger: 'blur'}
        ],
        //验证联系电话是否为空
        PhoneNumber1: [
          {required: true, message: '请输入你的电话号码', trigger: 'blur'}
        ],
        //验证紧急联系人姓名是否为空
        name2: [
          {required: true, message: '请输入紧急联系人的姓名', trigger: 'blur'}
        ],
        //验证紧急联系人的电话是否为空
        PhoneNumber2: [
          {required: true, message: '请输入紧急联系人的电话号码', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    add() {
      if (this.$data.list.name1
          && this.$data.list.name2
          && this.$data.list.birth
          && this.$data.list.sex
          && this.$data.list.IdNumber
          && this.$data.list.address
          && this.$data.list.PhoneNumber1
          && this.$data.list.PhoneNumber2 !== '') {
        return this.$message.success('登记成功')
        // this.$router.push('registration')
      }
      this.$message.error('登记失败！检查你还有什么没有填哦！')
    }
  }
}
</script>

<style Lang="less" scoped>
.list {
  position: absolute;
  left: 40%;
  top: 40%;
  transform: translate(-50%, -50%);
}

.el-input {
  width: 250px;
}

.el-checkbox {
  padding: 0;
}

h2 {
  text-align: center;
  padding-bottom: 25px;
  color: #ffffff;
}

.checkbox {
  width: 280px;
}

.picture {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: absolute;
  right: 16%;
  top: 46.5%;
  transform: translate(-50%, -50%);
  width: 188px;
  height: 288px;
  text-align: center;
}

.picture:hover {
  border-color: #409EFF;
}

.uppic {
  font-size: 58px;
  color: #8c939d;
  line-height: 248px;
}

.pic {
  position: absolute;
  left: 25%;
  top: 80%;
  height: 300px;
  width: 500px;
  text-align: center;
}

span {
  color: #fff;
  font-size: 20px;
  padding-bottom: 5px;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}

.a {
  position: absolute;
  right: 25%;
  top: 110%;
  height: 150px;
}
</style>
